package com.binvshe.binvshe.organization.tag;

import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.view.View;

import com.binvshe.binvshe.R;
import com.binvshe.binvshe.app.MyApplication;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;


/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/9/5
 */
public class TagBean implements Parcelable {
    public static final String KEY_TAG_BLUE = "TAG_BLUE";
    public static final String KEY_TAG_RED = "TAG_RED";
    private static final String KEY_TAG_DEEP_GREEN = "TAG_DEEP_GREEN";
    private static final String KEY_TAG_GREEN = "TAG_GREEN";
    public static final String KEY_TAG_TEXT_BLUE = "TAG_TEXT_BLUE";
    public static final String KEY_TAG_TEXT_RED = "TAG_TEXT_RED";


    private int id;
    @SerializedName("name")
    private String tagContent;
    @SerializedName("tag_type")
    private int tagType;
    private String tagBackGround;
    private String mTagTextColor;


    @ColorInt
    private int getColorRes(int id) {
        int res = MyApplication.getAppContext().getResources().getColor(id);
        return res;
    }

    private Drawable getDrawableRes(@DrawableRes int id) {
        Drawable res = MyApplication.getAppContext().getResources().getDrawable(id);
        return res;
    }

    /**
     * 获取测试数据
     *
     * @return
     */
    static public ArrayList<TagBean> getTestTagBean() {
        ArrayList<TagBean> datas = new ArrayList<>();
        TagBean bean1 = new TagBean();
        bean1.setTagBackGround(KEY_TAG_RED);
        bean1.setTagContent("御姐");
        bean1.setTagTextColor(KEY_TAG_TEXT_RED);
        datas.add(bean1);
        datas.add(bean1);
        datas.add(bean1);
        datas.add(bean1);
        datas.add(bean1);
        datas.add(bean1);
        datas.add(bean1);
        return datas;
    }

    /**
     * 给定默认的色值
     *
     * @param positon
     */
    public void setPositon(int positon) {
        int keyNum = positon % 4;
        switch (keyNum) {
            case 1:
                setTagTextColor(KEY_TAG_TEXT_RED);
                setTagBackGround(KEY_TAG_RED);
                break;
            case 0:
                setTagBackGround(KEY_TAG_BLUE);
                setTagTextColor(KEY_TAG_TEXT_BLUE);
                break;
            case 2:
                setTagBackGround(KEY_TAG_DEEP_GREEN);
                setTagTextColor(KEY_TAG_DEEP_GREEN);
                break;
            case 3:
                setTagBackGround(KEY_TAG_GREEN);
                setTagTextColor(KEY_TAG_GREEN);
                break;
            default:
                setTagBackGround(KEY_TAG_GREEN);
                setTagTextColor(KEY_TAG_GREEN);
        }
    }

    //通过key 获取文本颜色
    public int getTagTextColor() {
        @ColorInt int id = 0;
        switch (mTagTextColor) {
            case KEY_TAG_TEXT_BLUE:
                id = getColorRes(R.color.tagTextBlue);
                break;
            case KEY_TAG_TEXT_RED:
                id = getColorRes(R.color.tagTextRed);
                break;
            case KEY_TAG_DEEP_GREEN:
                id = getColorRes(R.color.tagTextDeepGreen);
                break;
            case KEY_TAG_GREEN:
                id = getColorRes(R.color.tagTextGreen);
                break;
        }
        return id;
    }

    //通过key 获取背景色
    public void getTagBackGround(View view) {
        @DrawableRes int res = -1;
        switch (tagBackGround) {
            case KEY_TAG_BLUE:
                res = R.drawable.tag_shadow_purple;
                break;
            case KEY_TAG_RED:
                res = R.drawable.tag_shadow_orange;
                break;
            case KEY_TAG_DEEP_GREEN:
                res = R.drawable.tag_shadow_deepgreen;
                break;
            case KEY_TAG_GREEN:
                res = R.drawable.tag_shadow_green;
                break;
            default:
                res = R.drawable.tag_shadow_orange;
        }
        view.setBackgroundResource(res);
        view.setPadding(20, 10, 20, 10);
    }

    public int getTagType() {
        return tagType;
    }

    public void setTagType(int tagType) {
        this.tagType = tagType;
    }

    public void setTagBackGround(String tagBackGround) {
        this.tagBackGround = tagBackGround;
    }

    public String getTagContent() {
        return tagContent;
    }

    public void setTagContent(String tagContent) {
        this.tagContent = tagContent;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setTagTextColor(String tagTextColor) {
        mTagTextColor = tagTextColor;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.tagContent);
        dest.writeString(this.tagBackGround);
        dest.writeString(this.mTagTextColor);
        dest.writeInt(this.tagType);
    }

    public TagBean() {
    }

    protected TagBean(Parcel in) {
        this.id = in.readInt();
        this.tagContent = in.readString();
        this.tagBackGround = in.readString();
        this.mTagTextColor = in.readString();
        this.tagType = in.readInt();
    }

    public static final Parcelable.Creator<TagBean> CREATOR = new Parcelable.Creator<TagBean>() {
        public TagBean createFromParcel(Parcel source) {
            return new TagBean(source);
        }

        public TagBean[] newArray(int size) {
            return new TagBean[size];
        }
    };
}
